package resources.lectureRoom;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import model.lectureRoom.Building;
import dao.LectureRoomDAO;
import dao.Linker;

public class LectureRoomsRes
{
	@Context
	UriInfo uriInfo;
	
	@Context
	Request request;
	
	String buildingId;
	
	public LectureRoomsRes(UriInfo uriInfo, Request request, String buildingId) 
	{
		this.uriInfo = uriInfo;
		this.request = request;
		this.buildingId = buildingId;
	}
	
	@GET
	@Produces(MediaType.TEXT_XML)
	public Building getDataBrowser()
	{
		Linker.sort();
		
		Building building = LectureRoomDAO.getBuildingsWithLectureRoomsCP().get(buildingId);
		
		if(building == null)
			throw new RuntimeException("Get: Building with lecture rooms " + buildingId + " not found");
		return building;
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Building getDataBrowserJSON() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XHTML_XML)
	public Building getDataBrowserXHTML() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XML)
	public Building getDataBrowserXML() 
	{
		return getDataBrowser(); 
	}
	
	@Path("{schedule}")
	public ScheduleRes getLectureRoomSchedule(@PathParam("schedule") String id) 
	{
		return new ScheduleRes(uriInfo, request, id);
	}
}